﻿/// <reference path="~/Scripts/lib/jquery-1.8.3.js" />
/// <reference path="config.js" />
/// <reference path="route-config.js" />
/// <reference path="presenter.js" />
/// <reference path="dataprimer.js" />
/// <reference path="binder.js" />

/**
 @title:        bootstrapper
 @description:  Module responsible for application start and initial configuration.
 @author:       Yuriy Shapovalov               
 */

define('bootstrapper',
    ['jquery', 'config', 'route-config', 'presenter', 'dataprimer', 'binder'],
    function ($, config, routeConfig, presenter, dataprimer, binder) {
        var
            run = function () {
                // show busy indicator
                presenter.toggleActivity(true);

                // ? not clear what this operation did
                config.dataserviceInit();

                $.when(dataprimer.fetch()) // request data from the server
                    .done(binder.bind) // bind view-models to views (templates)
                    .done(routeConfig.register) // Configure routes and running router. (Contain default router information)
                    .always(function () {
                        // hide busy indicator
                        presenter.toggleActivity(false);
                    });
            }

        return {
            run : run
        }
    });